package com.wu.easy.excel.starter.simple;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.core.utils.DataTransformUntil;
import org.wu.framework.easy.excel.stereotype.EasyExcel;
import org.wu.framework.easy.excel.stereotype.RequestExcelBody;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * description
 *
 * @author 吴佳伟
 * @company 杭州来回科技有限公司
 * @date 2022/1/25$ 4:36 下午$
 */
@Api(tags = "数据导出测试")
@RestController
@RequestMapping()
public class UserController {

    @EasyExcel(fileName = "导出数据")
    @GetMapping("/run/{size}")
    public List<UseExcel> run(@PathVariable Integer size) {
        List<UseExcel> useExcelList = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            UseExcel useExcel = new UseExcel();
            useExcel.setCurrentTime(LocalDateTime.MAX);
            useExcel.setDesc("默认方式导出数据");
            useExcel.setId(i);
            useExcel.setType("默认方式双注解导出");
            useExcelList.add(useExcel);
        }
        return useExcelList;
    }


    @GetMapping("/run/test/{size}")
    public Result<List<UseExcel>> test(@PathVariable Integer size) {
        List<UseExcel> useExcelList = DataTransformUntil.simulationBeanList(UseExcel.class, size);
        return ResultFactory.successOf(useExcelList);
    }

    @ApiOperation(value = "导入数据")
    @PostMapping("/import")
    public List<UseExcel> run(@RequestExcelBody("file") List<UseExcel> useExcelList ) {
        return useExcelList;
    }
}
